//
//  main.c
//  结构体
//
//  Created by szcq on 2021/5/7.
//

#include <stdio.h>

void test01() {
    struct Person {
        char *name;
        int age;
        double height;
    };
    struct Person p;
    /*
    数组不能先定义再进行一次性的初始化, 所有下面的写法是错误的
    p.name = "jkl";//Array type 'char [20]' is not assignable
     */
    p.name = "jkl";
    p.age = 10;
    p.height = 13.9;
    
    printf("");
    
    
}

void test02() {
    // 1.定义结构体类型并不会分配存储空间
    struct Person{
        int age; // 4
        int height; // 4
        int width; // 4
    };
    // 2.只有定义结构体变量才会真正的分配存储空间
    struct Person sp = {30, 1, 1};
    // 结构体第0个属性的地址就是结构体的地址
    printf("&sp = %p\n", &sp);//0x7ffeefbfeef0
    printf("age = %p\n", &sp.age);//0x7ffeefbfeef0
    
    printf("size = %lu\n", sizeof(sp));//12
    
    // 先存储第0个属性, 再依次存储其它属性
    printf("height = %p\n", &sp.height);//0x7ffeefbfeef4
    printf("width = %p\n", &sp.width);//0x7ffeefbfeef8
    
    
    struct Person *p = &sp;
    (*p).age = 40;
    p->height = 2;
    printf("");
}


int main(int argc, const char * argv[]) {
//    test01();
    test02();
    return 0;
}
